﻿using System;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using WindowsPhoneMvp.Util;

namespace WindowsPhoneMvp.Phone
{
    /// <summary>
    /// A base ViewModel implementation that implements INotifyPropertyChanged
    /// </summary>
    /// <typeparam name="TViewModel">The derived ViewModel type, this gives a strongly typed interface to RaisePropertyChanged(x => x.MyProp)</typeparam>
    [Obsolete("Use NotificationViewModel")]
    public abstract class NotificationViewModel<TViewModel> : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        protected void RaisePropertyChanged(Expression<Func<TViewModel, object>> property)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(Property.For(property)));
        }
    }

    /// <summary>
    /// A base ViewModel implementation that implements INotifyPropertyChanged
    /// </summary>
    public abstract class NotificationViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        protected void RaisePropertyChanged(Expression<Func<object>> property)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(Property.GetFor(property)));
        }
    }
}
